import { message } from 'antd';
import { fetchVipCard,fetchShopList,fetchSalesList,getMemberCardInfo,fetchAllVipCard } from '../service';

const Model = {
  namespace: 'cubeVipCardOper',
  state: {
    vipCard:{},
    shopList:[],
    salesList:[],
    allVipCard:[],
    salesList:[]
  },
  effects: {
    *fetchVipCard({ payload }, { call,put }) {
      let result=yield call(fetchVipCard, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            vipCard:result.data
          }
        });
        return result.data
      }else{
        message.error(result.message);
      }
    },
    *fetchShopList({ payload }, { call,put }) {
      let result=yield call(fetchShopList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            shopList:result.data          }
        });
      }else{
        message.error(result.message);
      }
    },
    *fetchSalesList({ payload }, { call,put }) {
      let result=yield call(fetchSalesList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            salesList:result.data          }
        });
      }else{
        message.error(result.message);
      }
    },
    *getMemberCardInfo({ payload }, { call,put }) {
      let result=yield call(getMemberCardInfo, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            vipCard:result.data          }
        });
      }else{
        message.error(result.message);
      }
    },
    *fetchAllVipCard({ payload }, { call,put }) {
      let result=yield call(fetchAllVipCard, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            allVipCard:result.data
          }
        });
      }else{
        message.error(result.message);
      }
    },
  },
  reducers: {
    common(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
export default Model;
